{% macro hours_to_days(hours) %}
    {% if hours < 24 %}
        {{ hours|int }}h
    {% else %}
        {{ "%.1f"|format(hours/24.0) }}d
    {% endif %}
{% endmacro %}

{% macro card_table(card_collection, request, caption="", show_done=False, show_state=True, show_priority=False, show_cycle=True, show_assigned=True, show_in_goal=True) -%}
<table>
    <caption>{{ caption }}</caption>
    <tr>
        <th class="key_col">Ticket</th>
        <th class="type_col">Type</th>
        <th class="sclass_col">Service Class</th>
        <th class="title_col">Title</th>



        {% if show_assigned %}
        <th>Assigned</th>
        {% endif %}

        {% if show_cycle %}
        <th>Cycle time</th>
        {% endif %}

        {% if show_done %}
        <th class="date_col">Done</th>
        {% endif %}

        {% if show_state %}
        <th>State</th>
        {% endif %}

        {% if show_priority %}
        <th>Ordering</th>
        {% endif %}

    </tr>

    {% for card in card_collection %}
    <tr class="{{ loop.cycle('odd', 'even') }} {% if card.blocked %}blocked{% endif %}" id="card_{{ card.key }}">
        <td>
            {% if card.ticket_system_data %}
                {% set icon = card.ticket_system_data.get('status', {}).get('icon').replace('http:', 'https:') %}
                {% set status_label = card.ticket_system_data.get('status', {}).get('name', '') %}
                {% if icon and 'closed' not in icon %}
                <img src="{{ icon }}" alt="{{ status_label }}" title="{{ status_label }}" width="16" height="16" />
                {% endif %}
            {% else %}
                <!--
                    {{ card.ticket_system_data }}
                -->
            {% endif %}
            <a href="{{ card.ticket_system.get_ticket_url() }}">{{ card.key }}
            </a>
        </td>

        <td>{{ card.type }}</td>

        <td>{{ card.service_class['name'] }}</td>

        <td>
            <a href="{{ url_for('card', key=card.key) }}">{{ card.ticket_system_data.get('summary', card.title) }}</a>
        </td>


        {% if show_assigned %}
        <td>
          {% if card.ticket_system_data %}
          {% set assignee = card.ticket_system_data.get('assignee', '') %}
          {% if assignee %}
          <a href="{{ url_for('person', name=assignee) }}">{{ assignee }}</a>{% endif %}
          {% endif %}
        </td>
        {% endif %}

        {% if show_cycle %}
            {% if card.cycle_in_goal and show_in_goal %}
            <td class="cycle_in_goal">
            {% elif card.cycle_over_goal %}
                <td class="cycle_over_goal">
            {% else %}
            <td>
            {% endif %}
                {% if card.cycle_time == 0 or card.cycle_time %}
                    {{ card.cycle_time }}
                {% else %}
                    {{ card.current_cycle_time() }}
                {% endif %}
            </td>
        {% endif %}


        {% if show_done %}
        <td class="date_col">
            {{ card.done_date.strftime("%Y-%m-%d") }}
        </td>
        {% endif %}
        {% if show_state %}
        <td>
            {% if card.state != 'Unknown' %}
                <a href="{{ url_for('state', state_slug=card.state|slugify) }}">{{ card.state }}</a>
            {% endif %}
        </td>
        {% endif %}

        {% if show_priority %}
        <td>
            {{ card.priority }}
        </td>
        {% endif %}

    </tr>
    {% endfor %}
</table>

{%- endmacro %}